package com.Wu.product.controller;

import com.Wu.product.model.Product;
import com.Wu.product.service.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/productInfo.do")
public class ProductInfoServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest rep, HttpServletResponse resp) throws ServletException, IOException {
        //获取商品编号
        String id = rep.getParameter("id");
        ProductService service = new ProductService();
        //使用服务层对象获取商品信息
        Product product = service.getProductById(id);
        //将信息存储到请求对象中
        rep.setAttribute("product",product);
        //跳转到商品详情页
        rep.getRequestDispatcher("product.jsp").forward(rep,resp);
    }
}

